//package faw.car.sdv.annotation;
//
//import android.sax.Element;
//
//import com.google.auto.service.AutoService;
//import com.google.gson.Gson;
//import com.google.gson.GsonBuilder;
//
//import java.io.IOException;
//import java.io.Writer;
//import java.util.HashMap;
//import java.util.Map;
//
//import javax.annotation.processing.AbstractProcessor;
//import javax.annotation.processing.RoundEnvironment;
//import javax.annotation.processing.SupportedAnnotationTypes;
//import javax.annotation.processing.SupportedSourceVersion;
//import javax.lang.model.SourceVersion;
//import javax.tools.FileObject;
//import javax.tools.StandardLocation;
//
//import faw.car.sdv.annotation.SdvAnnotations.SdvOpFunc;
//import faw.car.sdv.annotation.SdvAnnotations.SdvOpParameter;
//import faw.car.sdv.annotation.SdvAnnotations.SdvOpReturn;
//import faw.car.sdv.annotation.SdvAnnotations.SdvOperator;
//import faw.car.sdv.annotation.SdvAnnotations.SdvPackage;
//
//@AutoService(javax.annotation.processing.Processor.class)
//@SupportedAnnotationTypes({
//    "faw.car.sdv.annotation.SdvAnnotations.SdvPackage",
//    "faw.car.sdv.annotation.SdvAnnotations.SdvOperator",
//    "faw.car.sdv.annotation.SdvAnnotations.SdvOpFunc",
//    "faw.car.sdv.annotation.SdvAnnotations.SdvOpParameter",
//    "faw.car.sdv.annotation.SdvAnnotations.SdvOpReturn"
//})
//@SupportedSourceVersion(SourceVersion.RELEASE_8)
//public class SdvAnnotationProcessor extends AbstractProcessor {
//
//    private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
//
//    @Override
//    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
//        System.out.println("SdvAnnotationProcessor is processing annotations...");
//
//        Map<String, Map<String, String>> result = new HashMap<>();
//
//        // 处理 @SdvPackage 注解
//        for (Element element : roundEnv.getElementsAnnotatedWith(SdvPackage.class)) {
//            SdvPackage annotation = element.getAnnotation(SdvPackage.class);
//            Map<String, String> packageInfo = new HashMap<>();
//            packageInfo.put("name", annotation.name());
//            packageInfo.put("desc", annotation.desc());
//            packageInfo.put("version", annotation.version());
//            result.put("SdvPackage", packageInfo);
//        }
//
//        // 处理 @SdvOperator 注解
//        for (Element element : roundEnv.getElementsAnnotatedWith(SdvOperator.class)) {
//            SdvOperator annotation = element.getAnnotation(SdvOperator.class);
//            Map<String, String> operatorInfo = new HashMap<>();
//            operatorInfo.put("name", annotation.name());
//            operatorInfo.put("desc", annotation.desc());
//            result.put(element.getSimpleName().toString(), operatorInfo);
//        }
//
//        // 处理 @SdvOpFunc 注解
//        for (Element element : roundEnv.getElementsAnnotatedWith(SdvOpFunc.class)) {
//            SdvOpFunc annotation = element.getAnnotation(SdvOpFunc.class);
//            Map<String, String> funcInfo = new HashMap<>();
//            funcInfo.put("name", annotation.name());
//            funcInfo.put("desc", annotation.desc());
//            funcInfo.put("type", annotation.type());
//            result.put(element.getSimpleName().toString(), funcInfo);
//
//            // 处理方法参数
//            ExecutableElement methodElement = (ExecutableElement) element;
//            for (VariableElement param : methodElement.getParameters()) {
//                SdvOpParameter paramAnnotation = param.getAnnotation(SdvOpParameter.class);
//                if (paramAnnotation != null) {
//                    Map<String, String> paramInfo = new HashMap<>();
//                    paramInfo.put("name", paramAnnotation.name());
//                    paramInfo.put("desc", paramAnnotation.desc());
//                    paramInfo.put("type", paramAnnotation.type());
//                    paramInfo.put("validRange", paramAnnotation.validRange());
//                    result.put(param.getSimpleName().toString(), paramInfo);
//                }
//            }
//
//            // 处理方法返回值
//            SdvOpReturn returnAnnotation = methodElement.getAnnotation(SdvOpReturn.class);
//            if (returnAnnotation != null) {
//                Map<String, String> returnInfo = new HashMap<>();
//                returnInfo.put("name", returnAnnotation.name());
//                returnInfo.put("desc", returnAnnotation.desc());
//                returnInfo.put("type", returnAnnotation.type());
//                result.put(methodElement.getSimpleName().toString() + "_return", returnInfo);
//            }
//        }
//
//        // 将结果写入 JSON 文件
//        try {
//            FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "sdv_annotations.json");
//            System.out.println("Writing JSON to: " + file.toUri());
//            try (Writer writer = file.openWriter()) {
//                gson.toJson(result, writer);
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//        return true;
//    }
//}